package com.fdb.efp.flow.api.rest;

import java.util.List;
import java.util.Map;

import com.fdb.basic.framework.core.constant.PubConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fdb.efp.e4a.service.facade.SRoleDataRuleService;
import com.fdb.efp.flow.service.facade.BizStageInfoService;
import com.fdb.efp.flow.service.vo.BizStageInfoVO;
import com.fdb.basic.framework.core.constant.DataRuleType;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;

@RestController
@RequestMapping("/api")
public class BizStageInfoController extends AbstractController  {
	
	@Autowired
	@Qualifier("bizStageInfoService")
	private BizStageInfoService bizStageInfoService;
	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;

	
	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/biz/stage/infos", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<BizStageInfoVO>> queryBizStageInfoAll(
			@RequestBody BizStageInfoVO vo) {		
//		List<BizStageInfoVO> outputVo = this.executeQueryList("queryAll", bizStageInfoService, new Object[]{vo});
//		return getResponseData(outputVo);
		List<BizStageInfoVO> outputVo = null;
		// 根据用户角色获取用户权限方案
		//Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		//vo.setPrdCodebyBaseInfo(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PRD_CODE));
		//DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		DataRuleType dataRuleType =DataRuleType.getDataRuleType("01");
		//setUserInfoToVO(vo);
		// 根据权限方案调用不同的方案进行数据查询
		switch (dataRuleType) {
		case Owner:
			outputVo = bizStageInfoService.queryAllOwner(vo);
			break;
		case CurrOrg:
			outputVo = bizStageInfoService.queryAllCurrOrg(vo);
			break;
		case CurrDownOrg:
			outputVo = bizStageInfoService.queryAllCurrDownOrg(vo);
			break;
		default:
			outputVo = bizStageInfoService.queryAllOwner(vo);
			break;
		}
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据业务类型查询阶段信息
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/biz/stage/infoByFlowType", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<BizStageInfoVO>> queryBizStageInfoAllByFlowType(
			@RequestBody BizStageInfoVO vo) {	
		List<BizStageInfoVO> outputVo = bizStageInfoService.queryAllByFlowType(vo);
		return getResponseData(outputVo);
	}
	
	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/biz/stage/info/{bizStageId}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<BizStageInfoVO> queryByPk(@PathVariable("bizStageId") String bizStageId) {		
		BizStageInfoVO inVo = new BizStageInfoVO();
				inVo.setBizStageId(bizStageId);
		BizStageInfoVO outputVo = bizStageInfoService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键删除信息
	 * @param bizStageInfo
	 * @return
	 */
	@RequestMapping(value="/biz/stage/info", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody BizStageInfoVO inBizStageInfoVo) {		
		int outputVo = bizStageInfoService.deleteByPk(inBizStageInfoVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键更新信息
	 * @param inBizStageInfoVo
	 * @return
	 */
	@RequestMapping(value="/biz/stage/info", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody BizStageInfoVO inBizStageInfoVo) {		
		int outputVo = bizStageInfoService.updateByPk(inBizStageInfoVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 新增数据
	 * @param inBizStageInfoVo
	 * @return
	 */
	@RequestMapping(value="/biz/stage/info", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertBizStageInfo(@RequestBody BizStageInfoVO inBizStageInfoVo) {
		int outputVo = bizStageInfoService.insertBizStageInfo(inBizStageInfoVo);
		return getResponseData(outputVo);
		
	}
}
